import csv

csv_name = '开课情况表.csv'
with open(csv_name) as csv_file:
    csvReader = csv.reader(csv_file)
    csv_list = list(csvReader)

header = csv_list[0]
rows = csv_list[1:]
print(f"开课门数: {len(rows)}")

teacher_dict = {}
for row in rows:
    name = row[1]
    tea_name = row[4]
    hours = int(row[5]) + int(row[6])
    # print(f"课程名称: {name}, 主讲老师: {tea_name}")
    teacher_dict[tea_name] = teacher_dict.get(tea_name, 0) + hours

teacher_dict = sorted(teacher_dict.items(), key=lambda x: x[1], reverse=True)
print(f"{teacher_dict}")

with open('工作量.csv', 'w', encoding='UTF-8') as csv_file:
    csvWriter = csv.writer(csv_file, lineterminator='\n')
    csvWriter.writerow(['老师', '工作量'])

    for x in teacher_dict:
        csvWriter.writerow([x[0], x[1]])
